#ifndef  __FLASH_H__
#define  __FLASH_H__

#include "type.h"
#include "list.h"
//----------------------------------------------struct in flash
typedef struct _st_sensor_funit
{
	u08	flag;
	u08	io_idx;
	u08	x_idx;
	u08	y_idx;
	u08	romid[8];
}st_sensor_funit;
//}__attribute__((packed)) st_sensor_funit;

typedef struct _st_sensor_fdata
{
	st_sensor_funit	funit;
	list_node_t 	node;
}st_sensor_fdata;
//}__attribute__((packed)) st_sensor_fdata;
//-----------------------------------------------
typedef struct _st_sensor_munit
{
	u08	io_idx;
	u08	y_idx;
	u16	rom_addr;
}st_sensor_munit;
//}__attribute__((packed)) st_sensor_munit;

typedef struct _st_sensor_mdata
{
	st_sensor_munit	munit;
	list_node_t 	node;
}st_sensor_mdata;
//}__attribute__((packed)) st_sensor_munit;
//-----------------------------------------------


#define FLASH_SIZE				0x20000 //128K
#define FLASH_PAGE_SIZE			256
#define FLASH_ADDR_SUPER_BLOCK	256 	//0x10000UL //64KB
#define SUPER_BLOCK_DUMMY		0x55AA55AA
#define	FLAG_FLASH_PROGRAMED	0x01


#define FUNIT_COUNTS_PER_PAGE	(FLASH_PAGE_SIZE/sizeof(st_sensor_funit))
#define MUNIT_COUNTS_PER_PAGE	(FLASH_PAGE_SIZE/sizeof(st_sensor_munit))

typedef struct _st_flash_superblock
{
	u32	dummy;
	u08	programed;
	u08	flag_test[3];
	u16	programed_cnt;
	u16	sensor_cnt;
	u16	page_start;
	u16	page_end;
}st_flash_sb;
//the superblock item from filesystem in linux




void	flash_sb_init(st_flash_sb*sb);
s16		flash_sb_rewrite(st_flash_sb*sb);

void 	mempool_deinit(void);
void	mempool_sensor_fdata_init(u08*start_addr,u16 unit_cnt);
void 	mempool_sensor_mdata_init(u08*start_addr,u16 unit_cnt);
st_sensor_fdata*	mempool_sensor_fdata_get(void);
st_sensor_mdata* 	mempool_sensor_mdata_get(void);

#define TEST_IN_HOST	1

#endif






